import type { BrowserWindow } from 'electron'
import { app, Menu } from 'electron'

import { useStore } from './store'
import { mac } from '../util'

export function initMenu(win: BrowserWindow) {
  const store = useStore()
  const userInfo = store.getUserInfo()

  let helpMenu
  if (userInfo.role) {
    helpMenu = [{
      label: '清除缓存',
      click() {
        win.webContents.session.clearStorageData()
      }
    }]
  } else {
    if(mac()) {
      helpMenu = [
        { label: '版本号：'+ app.getVersion() }
      ]
    } else {
      helpMenu = [
        {
          label: '关于',
          click() {
            win.webContents.send('show-phone')
          }
        }
      ]
    }
  }

  const template = [
    {
      label: '版本号：'+ app.getVersion(),
      submenu: helpMenu
    }
  ]
  Menu.setApplicationMenu(Menu.buildFromTemplate(template))
}
